package cn.edu.scau.dao;

import cn.edu.scau.entity.RecoveryRegister;
import org.apache.ibatis.jdbc.SQL;

/**
 * 数据访问层 RecoveryRegisterSqlProvider： 是接口RecoveryRegisterkMapper的补充，专门编写复杂的SQL语句
 * @author LLLegend
 *
 */
public class RecoveryRegisterSqlProvider {

    public String insertSelective(RecoveryRegister record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("recoveryregister");
        
        if (record.getRecoveryRegisterID() != null) {
            sql.VALUES("recoveryRegisterID", "#{recoveryRegisterID,jdbcType=INTEGER}");
        }
        
        if (record.getNurseID() != null) {
            sql.VALUES("nurseID", "#{nurseID,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerID() != null) {
            sql.VALUES("customerID", "#{customerID,jdbcType=INTEGER}");
        }
        
        if (record.getRecoveryRegisterPlan() != null) {
            sql.VALUES("recoveryRegisterPlan", "#{recoveryRegisterPlan,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(RecoveryRegister record) {
        SQL sql = new SQL();
        sql.UPDATE("recoveryregister");
        
        if (record.getNurseID() != null) {
            sql.SET("nurseID = #{nurseID,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerID() != null) {
            sql.SET("customerID = #{customerID,jdbcType=INTEGER}");
        }
        
        if (record.getRecoveryRegisterPlan() != null) {
            sql.SET("recoveryRegisterPlan = #{recoveryRegisterPlan,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("recoveryRegisterID = #{recoveryRegisterID,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    
    public String find(Integer recoveryRegisterID,Integer nurseID,String nurseName,Integer customerID,String customerName){
        SQL sql = new SQL();
        sql.SELECT("recoveryRegisterID, nurseID, nurseName, customerID, customerName, recoveryRegisterPlan");
        sql.FROM("recoveryregister natural join customer natural join nurse");
        if(recoveryRegisterID!=null){
            sql.WHERE(" recoveryRegisterID like concat('%',#{recoveryRegisterID},'%')");
        }
        if(nurseID!=null){
            sql.WHERE(" nurseID like concat('%',#{nurseID},'%')");
        }
        if(nurseName!=null){
            sql.WHERE(" nurseName like concat('%',#{nurseName},'%')");
        }
        if(customerID!=null){
            sql.WHERE(" customerID like concat('%',#{customerID},'%')");
        }
        if(customerName!=null){
            sql.WHERE(" customerName like concat('%',#{customerName},'%')");
        }
        return sql.toString();
    }
    
    public String findWithNurseID(Integer recoveryRegisterID,Integer nurseID,Integer customerID,String customerName){
        SQL sql = new SQL();
        sql.SELECT("recoveryRegisterID, nurseID, nurseName, customerID, customerName, recoveryRegisterPlan");
        sql.FROM("recoveryregister natural join customer natural join nurse");
        if(recoveryRegisterID!=null){
            sql.WHERE(" recoveryRegisterID like concat('%',#{recoveryRegisterID},'%')");
        }
        if(nurseID!=null){
            sql.WHERE(" nurseID = #{nurseID}");
        }
        if(customerID!=null){
            sql.WHERE(" customerID like concat('%',#{customerID},'%')");
        }
        if(customerName!=null){
            sql.WHERE(" customerName like concat('%',#{customerName},'%')");
        }
        return sql.toString();
    }
}